package com.juli.school.app.controller.module;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.juli.school.dao.entity.Pub;
import com.juli.school.service.bo.NewsBo;
import com.juli.school.service.bo.RecBo;
import com.juli.school.service.enums.EnumModule;
import com.juli.school.service.impl.NewsService;
import com.juli.school.service.impl.RecService;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.ListResp;
import com.juli.school.utils.core.model.PageResp;

/**
 * @Description: 新闻控制器
 * @author: Eve
 * @date: 2017/8/31.
 */
@Controller
@RequestMapping("/news")
public class NewsController {
	
	@Resource
	NewsService newsService;
	
	@Resource
	RecService recService;
	
	@RequestMapping("/gotoDetail")
	String gotoDetail(Model model) {
		model.addAttribute("type", "news");
		model.addAttribute("detail", "今天发生了一件大事");
		return "detail/index";
	}
	
	/**
	 * @Description: 分页查询新闻列表
	 * @author gaoxiang
	 * @date 2017年11月22日 下午4:45:53
	 */
	@RequestMapping("/listPage")
	@ResponseBody CommonResp<PageResp<Pub>> listPage(NewsBo newsBo) {
		return newsService.listPage(newsBo);
	}
	
	/**
	 * @Description: 增量查询信息列表
	 * @author gaoxiang
	 * @date 2017年9月16日 下午10:27:17
	 */
	@RequestMapping("/list")
	@ResponseBody CommonResp<ListResp<Pub>> list(NewsBo req) {
		req.setType(EnumModule.News.code);
		return newsService.list(req);
	}
	
	/**
	 * @Description: 获取新闻详情
	 * @author gaoxiang
	 * @date 2017年11月22日 下午4:46:04
	 */
	@RequestMapping("/detail")
	@ResponseBody CommonResp<NewsBo> detail(NewsBo newsBo) {
		return newsService.detail(newsBo);
	}
	
	@RequestMapping("detailer")
	public String detailer(NewsBo newsBo,ModelMap model){
		model.put("type", EnumModule.News);
		CommonResp<List<RecBo>> list = recService.list(newsBo.getSnStamp());
		model.put("recs", list.getData());
		model.put("obj",  newsService.detail(newsBo));
		return "/detail/index";
	}
}
